﻿// <copyright file="Unique.cs" company="Community Combat Simulator">
//    Community Combat Simulator: a free combat flight simulator.
//    Copyright (C) 2008 Aaron Schinkowitch
//
//    This program is free software: you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    (at your option) any later version.
//
//    This program is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License
//    along with this program.  If not, see http://www.gnu.org/licenses/.
// </copyright>
namespace CCSim.Util
{
    using System;

    /// <summary>
    /// Gets unique numbers to use in unit tests.
    /// </summary>
    public sealed class Unique
    {
        /// <summary>
        /// The most recently used integer value.
        /// </summary>
        private static int lastInteger = 1;
        
        /// <summary>
        /// Random number generator.
        /// </summary>
        private static Random random = new Random();
        
        /// <summary>
        /// Prevents a default instance of the Unique class from being created.
        /// </summary>
        private Unique()
        {    
        }

        /// <summary>
        /// Gets a unique double. The same value will likely never be returned twice
        /// within one run of the runtime.
        /// </summary>
        /// <returns>A unique floating point number.</returns>
        public static double Double()
        {
            double value = PositiveDouble();
            
            if (random.NextDouble() >= 0.5) 
            {
                value = -value;
            }
            
            return value;
        }
        
        /// <summary>
        /// Gets a unique positive double. The same value will likely never be returned twice
        /// within one run of the runtime. 
        /// </summary>
        /// <returns>A unique floating point number greater than zero.</returns>
        public static double PositiveDouble() 
        {
            double value = lastInteger++;
            
            value += random.NextDouble();
            
            return value;
        }
        
        /// <summary>
        /// Gets a unique positive int. The same value will likely never be returned twice
        /// within one run of the runtime.
        /// </summary>
        /// <returns>A positive whole number.</returns>
        public static int PositiveInt()
        {
            return lastInteger++;
        }
    }
}
